package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.Notice;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import com.zrwl.poscloud.xo.mapper.NoticeMapper;
import com.zrwl.poscloud.xo.service.NoticeService;
import com.zrwl.poscloud.xo.vo.NoticeVO;

import javax.annotation.Resource;

/**
 * 公告发布 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-09
 */
@Service
public class NoticeServiceImpl extends SuperServiceImpl<NoticeMapper,Notice> implements NoticeService {

    @Autowired
    private NoticeService noticeService;
    @Resource NoticeMapper noticeMapper;
    @Override
    public IPage<NoticeVO> getPageList(NoticeVO noticeVO){
       Page<NoticeVO> page = new Page<>();
       page.setCurrent(noticeVO.getCurrentPage());
       page.setSize(noticeVO.getPageSize());
       IPage<NoticeVO> pageList = noticeMapper.getPageList(page, noticeVO);
       List<NoticeVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<Notice> getAllList(NoticeVO noticeVO){
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<Notice> list = noticeService.list(queryWrapper);
        return list;
}
    @Override
    public String add(NoticeVO noticeVO){
        Notice entity = new Notice();
        BeanUtils.copyProperties(noticeVO, entity, SysConf.STATUS);
        entity.insert();
        noticeVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(NoticeVO noticeVO){
        Notice entity = noticeService.getById(noticeVO.getUid());
        BeanUtils.copyProperties(noticeVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(NoticeVO noticeVO){
        Notice entity = noticeService.getById(noticeVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
